package com.zrfintech.service;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.google.common.collect.Lists;
import com.zrfintech.domain.MgUserRole;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class MgUserRoleRepo extends MgUserRoleRepoI {
    public List<String> getRoleCodeListByUserCode(String userCode) {
        QueryWrapper<MgUserRole> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(USER_CODE_COLUMN, userCode);
        List<MgUserRole> mgUserRoleList = dao.selectList(queryWrapper);
        return CollectionUtil.isEmpty(mgUserRoleList)
                ? Lists.newArrayList()
                : mgUserRoleList.stream()
                .map(MgUserRole::getRoleCode).collect(Collectors.toList());
    }

    public int deleteByUserCode(String userCode) {
        QueryWrapper<MgUserRole> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(USER_CODE_COLUMN, userCode);
        return dao.delete(queryWrapper);
    }
}
